package by.onlinernews.newsfull;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MyWebViewClient extends WebViewClient {

	private Context context;

	public MyWebViewClient(Context context) {

		this.context = context;

	}

	@Override
	public boolean shouldOverrideUrlLoading(WebView view, String url) {

		if (url.indexOf("activity-run://ImageActivity") != -1) {
			Intent intent = new Intent(context, ImageActivity.class);
			int indexname = url.indexOf("http");
			String link = url.substring(indexname, url.length());
			Log.d("html", "link url = " + url);
			Log.d("html", "result link = " + link);
			intent.putExtra("image_link", link);
			context.startActivity(intent);
			return true;
		}
		else {
			Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
			context.startActivity(browserIntent);
			return true;
		}
	}
}
